<?php
class ModelCoreOnline extends Model
{
	function getItem($id)
	{
		$sql="select * from `online` where onlineid='".$id."'";
		$row=$ob->singleData($sql);
		$query = $this->db->query($sql);		
		return $query->row;
	}

	function getList($dk)
	{
		$sql="select * from `online` $dk";
		$query = $this->db->query($sql);		
		return $query->rows;
	}
	
	function insert($data)
	{
		$onlineid=$this->db->getNextIdVarChar("online","onlineid","online");
		$ip = $data['ip'];
		$onlinetime = $data['onlinetime'];
		$field=array("onlineid","ip","onlinetime");
		$value=array($onlineid,$ip,$onlinetime);
		$this->db->insertData("online",$field,$value);
	}
	
	function update($data)
	{
		$onlineid=$data['onlineid'];
		$ip = $data['ip'];
		$onlinetime = $data['onlinetime'];
		$field=array("onlineid","ip","onlinetime");
		$value=array($onlineid,$ip,$onlinetime);
		$where=" onlineid = '".$onlineid."'";
		$this->db->updateData($conn,"online",$field,$value,$where);
	}

	function delete($onlineid)
	{
		$ob=new ClassConnect();
		$where=" onlineid = '".$onlineid."'";
		
		return $this->db->deleteData($conn,"online",$where);
	}
	
	function countOnline()
	{
		$time=$this->date->addMinutes($this->date->getToday(),-20);
		$where="`onlinetime` <= '".$time."'";
		$this->db->deleteData("online",$where);
		$data=$this->getList(" GROUP BY ip");
		return count($data);
	}
	
	function exportListBlackIP()
	{
		
		$sql="SELECT *,count(`ip`) as Count FROM `online` Group by `ip`";
		$data=$query = $this->db->query($sql);
		$arr=array();
		foreach($data as $item)
		{
			if($item['Count']>20)
				$arr[]=$item['ip'];
		}
		$list=implode(',',$arr);
		$fp = fopen('blacklist.txt', 'w');
		fwrite($fp, $list);
		fclose($fp);
	}
	
}
?>